package com.hw.paltfrom.service.casemain;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.exception.HWSystemException;
import com.hw.paltfrom.mapper.HwBaseAnnexesfileMapper;
import com.hw.paltfrom.mapper.HwCaseFileMapper;
import com.hw.paltfrom.mapper.HwCaseMainMapper;
import com.hw.paltfrom.mapper.HwCasePoliceoperMapper;
import com.hw.paltfrom.mapper.HwCaseSiteoperMapper;
import com.hw.paltfrom.mapper.HwCaseSrccomMapper;
import com.hw.paltfrom.mapper.HwDataOverrunstationHistoryMapper;
import com.hw.paltfrom.mapper.HwDataOverrunstationOverweightMapper;
import com.hw.paltfrom.mapper.HwSupervisionMapper;
import com.hw.paltfrom.pojo.HwBaseAnnexesfile;
import com.hw.paltfrom.pojo.HwCaseMain;
import com.hw.paltfrom.pojo.HwCasePoliceoper;
import com.hw.paltfrom.pojo.HwCaseSiteoper;
import com.hw.paltfrom.pojo.HwCaseSrccom;
import com.hw.paltfrom.pojo.HwCommandWorkflow;
import com.hw.paltfrom.pojo.HwDataOverrunstationHistory;
import com.hw.paltfrom.pojo.HwDataOverrunstationOverweight;
import com.hw.paltfrom.pojo.HwSupervision;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.service.doncutor.CommandWorkflowService;
import com.hw.paltfrom.utils.PageUtils;
import com.hw.paltfrom.utils.RandomNumberUtil;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.vo.CasePoliceoperVo;
import com.hw.paltfrom.vo.CaseSrccomVo;
import com.hw.paltfrom.vo.CountryCasemainVo;
import com.hw.paltfrom.vo.FileInfo;
import com.hw.paltfrom.vo.StepInfoVO;
import com.hw.paltfrom.vo.SupervisionVo;

/**
 * 县执法监管 邢家华 2019-11-15 13:50:25
 * 
 * @author Administrator
 *
 */
@Service
public class CountryCasemainServer {

	@Autowired
	private HwCaseMainMapper hwCaseMainMapper;

	@Autowired
	private HwBaseAnnexesfileMapper hwBaseAnnexesfileMapper;

	@Autowired
	private CommandWorkflowService commandWorkflowService;

	@Autowired
	private HwCaseSiteoperMapper hwCaseSiteoperMapper;

	// 超重车辆表的接口
	@Autowired
	private HwDataOverrunstationOverweightMapper dataOverrunstationOverweightMapper;

	@Autowired
	private HwSupervisionMapper hwSupervisionMapper;

	@Autowired
	private HwDataOverrunstationHistoryMapper hwDataOverrunstationHistoryMapper;

	@Autowired // HW_Case_File 案件文书上传表
	private HwCaseFileMapper hwCaseFileMapper;

	@Autowired // HW_Case_PoliceOper 案件交警执法
	private HwCasePoliceoperMapper hwCasePoliceoperMapper;
	@Autowired // 源头倒查表 ：HW_Case_SrcCom
	private HwCaseSrccomMapper hwCaseSrccomMapper;

	// 查询
	public Map<String, Object> query(CountryCasemainVo vo) {

		// 分页
		Integer pageNum = vo.getPageNum();
		Integer pageSize = vo.getPageSize();
		// 筛选条件
		// 办理状态完结、 执行中
		String fAjCrtstep = vo.getfAjCrtstep();
		// 行政区编码
		String fAreaCode = vo.getFareacode();
		// 县选中的超限站编号
		String overrunCode = vo.getfOverruncode();
		// 车牌号模糊
		String fClTruckno = vo.getfClTruckno();
		// 超限吨数
		Double fClOverweight = vo.getfClOverweight();
		// 高级查询
		// 轴数
		String fClAxis = vo.getfClAxis();
		// 检测开始时间
		Timestamp startTime = vo.getStartTime();
		// 检测结束时间
		Timestamp endTime = vo.getEndTime();
		// 责任倒查
		Integer fAjInvestigate = vo.getfAjInvestigate();
		// 交警处罚
		Integer fAjPolice = vo.getfAjPolice();
		// 放行类型
		Integer fAjGostate = vo.getfAjGostate();

		Wrapper<HwCaseMain> wrapper = new EntityWrapper<HwCaseMain>();
		// 车牌号模糊
		if (StringUtils.isNotBlank(fClTruckno)) {
			wrapper.like("F_CL_TruckNo", fClTruckno);
		}
		// 办理状态完结、 执行中
		if (StringUtils.isNotBlank(fAjCrtstep)) {
			wrapper.eq("F_AJ_CrtStep", fAjCrtstep);
		} else {
			wrapper.ne("F_AJ_CrtStep", "07");
		}
		// 超限吨数
		if (StringUtils.isNotBlank(vo.getSymbol()) && fClOverweight != null) {
			switch (vo.getSymbol()) {
			case "1":
				wrapper.ge("F_CL_OverWeight", fClOverweight);
				break;
			case "-1":
				wrapper.le("F_CL_OverWeight", fClOverweight);
				break;
			case "0":
				wrapper.eq("F_CL_OverWeight", fClOverweight);
				break;
			}

		}
		// 轴数
		if (StringUtils.isNotBlank(vo.getSymbol1()) && fClAxis != "") {
			switch (vo.getSymbol1()) {
			case "1":
				wrapper.ge("F_CL_Axis", fClAxis);
				break;
			case "-1":
				wrapper.le("F_CL_Axis", fClAxis);
				break;
			case "0":
				wrapper.eq("F_CL_Axis", fClAxis);
				break;
			}

		}
		// 检测时间
		if (startTime != null && endTime != null) {
			wrapper.between("F_CreateTime", startTime, endTime);
		}
		// 责任倒查
		if (fAjInvestigate != null) {
			wrapper.eq("F_AJ_Investigate", fAjInvestigate);
		}
		// 交警处罚

		if (fAjPolice != null) {
			wrapper.eq("F_AJ_Police", fAjPolice);
		}
		// 放行类型
		if (fAjGostate != null) {
			wrapper.eq("F_AJ_GoState", fAjGostate);
		}
		if (StringUtils.isNotBlank(overrunCode)) {
			wrapper.eq("F_OverrunCode", overrunCode);
		}
		wrapper.eq("F_AreaCode", fAreaCode).orderBy("F_CreateTime", false);

		List<HwCaseMain> hwCaseMainList = hwCaseMainMapper.selectList(wrapper);
		// 分页
		PageUtils<CountryCasemainVo> pageUtils = new PageUtils<CountryCasemainVo>(pageNum, pageSize);
		List<CountryCasemainVo> countryCasemainVoList = new ArrayList<CountryCasemainVo>();
		for (HwCaseMain hwCaseMain : hwCaseMainList) {
			CountryCasemainVo countryCasemainVo = new CountryCasemainVo();
			countryCasemainVo.setfCaseid(hwCaseMain.getfCaseid());
			countryCasemainVo.setfOverruncode(hwCaseMain.getfOverruncode());
			countryCasemainVo.setfOverrunname(hwCaseMain.getfOverrunname());
			countryCasemainVo.setfClTruckno(hwCaseMain.getfClTruckno());
			countryCasemainVo.setfClAxis(hwCaseMain.getfClAxis());
			countryCasemainVo.setfClTotalweight(hwCaseMain.getfClTotalweight());
			countryCasemainVo.setfClOverweight(hwCaseMain.getfClOverweight());
			countryCasemainVo.setfClChecktime(hwCaseMain.getfClChecktime());
			countryCasemainVo.setfAjCrtstep(hwCaseMain.getfAjCrtstep());
			countryCasemainVo.setfAjInvestigate(hwCaseMain.getfAjInvestigate());
			countryCasemainVo.setfAjPoliceamount(hwCaseMain.getfAjPoliceamount());
			countryCasemainVo.setfAjPolicescore(hwCaseMain.getfAjPolicescore());
			countryCasemainVo.setfAjPolice(hwCaseMain.getfAjPolice());
			countryCasemainVo.setfAjGostate(hwCaseMain.getfAjGostate());
			countryCasemainVo.setFlowCode(hwCaseMain.getFlowCode());
			// 立案审核按钮1显示
			if (hwCaseMain.getfAjCrtstep().equals("03")) {
				countryCasemainVo.setInitiateAnAudit(1);
			}
			// 放行
			if (hwCaseMain.getfAjCrtstep().equals("04") && hwCaseMain.getfAjInvestigate() != 0
					&& hwCaseMain.getfAjPolice() == 1) {
				countryCasemainVo.setRelease(1);
			}
			// 完结审核
			if (hwCaseMain.getfAjCrtstep().equals("06")) {
				countryCasemainVo.setAuditEnd(1);
			}

			countryCasemainVoList.add(countryCasemainVo);
		}
		Object info = pageUtils.getPageResult(countryCasemainVoList);
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, info);
	}

	// 立案审核
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> initiateAnAudit(StepInfoVO vo) {
		Wrapper<HwCaseMain> wrapper = new EntityWrapper<HwCaseMain>();
		wrapper.eq("F_CaseId", vo.getTaskId());
		HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(vo.getTaskId());
		if (!hwCaseMain.getfAjCrtstep().equals("03")) {
			return ResponeResultUtil.success(HWSystemCode.AUDIT);
		} else {
			if (vo.getWorkflowDoresult() == 0) {
				hwCaseMain.setfAjCrtstep(vo.getWorkflowNextcode());
				hwCaseMain.setfAjReturntimes(vo.getWorkflowDoresult());
				Integer update = hwCaseMainMapper.update(hwCaseMain, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			} else {
				hwCaseMain.setfAjCrtstep(vo.getWorkflowNextcode());
				hwCaseMain.setfAjReturntimes(vo.getWorkflowDoresult());
				Integer update = hwCaseMainMapper.update(hwCaseMain, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			}
			// 附件新增
			String fFolderid = RandomNumberUtil.getNumber();
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZFJGFILE执法监管");
				hwBaseAnnexesfile.setFileName("立案审核附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfCreateuserid(vo.getLoginUser());
				hwBaseAnnexesfile.setfFolderid(fFolderid);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}

			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(fFolderid);
			hwCommandWorkflow.setWorkflowNextcode(vo.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(vo.getWorkflowNextname());
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}

	}

	// 放行
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> release(StepInfoVO vo) {

		Wrapper<HwCaseMain> wrapper = new EntityWrapper<HwCaseMain>();
		wrapper.eq("F_CaseId", vo.getTaskId());
		HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(vo.getTaskId());
		String fFolderid = RandomNumberUtil.getNumber();
		if (!(hwCaseMain.getfAjCrtstep().equals("04") && hwCaseMain.getfAjInvestigate() != 0
				&& hwCaseMain.getfAjPolice() == 1)) {
			return ResponeResultUtil.success(HWSystemCode.RELEASE);
		} else {

			if (vo.getWorkflowDoresult() == 0) {
				hwCaseMain.setfAjCrtstep(vo.getWorkflowNextcode());
				hwCaseMain.setfAjReturntimes(vo.getWorkflowDoresult());
				Integer update = hwCaseMainMapper.update(hwCaseMain, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}

			} else {
				hwCaseMain.setfAjCrtstep(vo.getWorkflowNextcode());
				hwCaseMain.setfAjReturntimes(vo.getWorkflowDoresult());
				Integer update = hwCaseMainMapper.update(hwCaseMain, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			}

			// 案件站点办理表更新
			Wrapper<HwCaseSiteoper> operwrapper = new EntityWrapper<HwCaseSiteoper>();
			operwrapper.eq("F_MainId", vo.getTaskId());
			HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
			hwCaseSiteoper.setfGoannex(fFolderid);
			Integer hupdate = hwCaseSiteoperMapper.update(hwCaseSiteoper, operwrapper);
			if (hupdate != 1) {
				throw new HWSystemException();
			}
			// 附件新增
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZFJGFILE执法监管");
				hwBaseAnnexesfile.setFileName("放行附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfCreateuserid(vo.getLoginUser());
				hwBaseAnnexesfile.setfFolderid(fFolderid);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}

			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(fFolderid);
			hwCommandWorkflow.setWorkflowNextcode(vo.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(vo.getWorkflowNextname());
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}
	}

	// 完结审核
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> auditEnd(StepInfoVO vo) {
		Wrapper<HwCaseMain> wrapper = new EntityWrapper<HwCaseMain>();
		wrapper.eq("F_CaseId", vo.getTaskId());
		HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(vo.getTaskId());
		if (!hwCaseMain.getfAjCrtstep().equals("06")) {
			return ResponeResultUtil.success(HWSystemCode.AUDIT_END);
		} else {
			if (vo.getWorkflowDoresult() == 0) {
				hwCaseMain.setfAjCrtstep(vo.getWorkflowNextcode());
				hwCaseMain.setfAjReturntimes(vo.getWorkflowDoresult());
				hwCaseMain.setfAjEndtime(new Timestamp(System.currentTimeMillis()));
				Integer update = hwCaseMainMapper.update(hwCaseMain, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			} else {
				hwCaseMain.setfAjCrtstep(vo.getWorkflowNextcode());
				hwCaseMain.setfAjReturntimes(vo.getWorkflowDoresult());
				Integer update = hwCaseMainMapper.update(hwCaseMain, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			}
			// 附件新增
			String fFolderid = RandomNumberUtil.getNumber();
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZFJGFILE执法监管");
				hwBaseAnnexesfile.setFileName("审核完结附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfCreateuserid(vo.getLoginUser());
				hwBaseAnnexesfile.setfFolderid(fFolderid);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}

			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			if(!fileInfoList.isEmpty()){
				hwCommandWorkflow.setfAnnexes(fFolderid);
			}
			hwCommandWorkflow.setWorkflowNextcode(vo.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(vo.getWorkflowNextname());
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}
	}

	// 详情
	public Map<String, Object> queryDetails(String fCaseid) {

		HashMap<String, Object> result = new HashMap<String, Object>();
		// 案件表
		HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(fCaseid);
		if (hwCaseMain.getfAjCasetype() != null) {
			
			// 案件站点办理表更新
			HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
			hwCaseSiteoper.setfMainid(fCaseid);
			HwCaseSiteoper hCaseSiteoper = hwCaseSiteoperMapper.selectOne(hwCaseSiteoper);
			result.put("HwCaseSiteoper", hCaseSiteoper);
			// 案件附件表
			List<HwBaseAnnexesfile> hwBaseAnnexesfilelist = new ArrayList<HwBaseAnnexesfile>();
			if (hCaseSiteoper.getfFirstviewannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfFirstviewannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist1 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist1);

			}
			if (hCaseSiteoper.getfReviewannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfReviewannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist2 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist2);

			}
			if (hCaseSiteoper.getfTranannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfTranannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist3 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist3);
			}
			if (hCaseSiteoper.getfCopyannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfCopyannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist4 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist4);
			}
			if (hCaseSiteoper.getfFourlicannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfFourlicannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist5 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist5);
			}

			result.put("HwBaseAnnexesfile", hwBaseAnnexesfilelist);

			// HW_Case_File 案件文书上传表
			List<Map<String, Object>> maps = hwCaseFileMapper.dyGetUserList(fCaseid, hwCaseMain.getfAjCasetype());
			result.put("HwCaseFile", maps);
		}
		result.put("HwCaseMain", hwCaseMain);
		// 超重数据
		HwDataOverrunstationOverweight weight = dataOverrunstationOverweightMapper
				.selectById(hwCaseMain.getfOverrunid());
		result.put("HwDataOverrunstationOverweight", weight);
		// 督导表
		EntityWrapper<HwSupervision> supervision = new EntityWrapper<HwSupervision>();
		supervision.eq("F_FromObjectID", fCaseid);
		List<HwSupervision> hwSupervisions = hwSupervisionMapper.selectList(supervision);
		List<SupervisionVo> supervisionVo = new ArrayList<>();
		for (HwSupervision hwSupervision1 : hwSupervisions) {
			SupervisionVo supervisionVo1 = new SupervisionVo();
			supervisionVo1.setfSpvid(hwSupervision1.getfSpvid());
			supervisionVo1.setfFromobjectid(hwSupervision1.getfFromobjectid());
			supervisionVo1.setfFromtype(hwSupervision1.getfFromtype());
			supervisionVo1.setfFromdepcode(hwSupervision1.getfFromdepcode());
			supervisionVo1.setfFromuserid(hwSupervision1.getfFromuserid());
			supervisionVo1.setfFromusername(hwSupervision1.getfFromusername());
			supervisionVo1.setfFromtime(hwSupervision1.getfFromtime());
			supervisionVo1.setfTitle(hwSupervision1.getfTitle());
			supervisionVo1.setfFromsrc(hwSupervision1.getfFromsrc());
			supervisionVo1.setfSpvcontent(hwSupervision1.getfSpvcontent());
			supervisionVo1.setfCurrentstep(hwSupervision1.getfCurrentstep());
			supervisionVo1.setfBacktype(hwSupervision1.getfBacktype());
			supervisionVo1.setfBackdepcode(hwSupervision1.getfBackdepcode());
			supervisionVo1.setfBackdepname(hwSupervision1.getfBackdepname());
			supervisionVo1.setfBackuserid(hwSupervision1.getfBackuserid());
			supervisionVo1.setfBackusername(hwSupervision1.getfBackusername());
			supervisionVo1.setfBackuserphone(hwSupervision1.getfBackuserphone());
			supervisionVo1.setfBacktime(hwSupervision1.getfBacktime());
			supervisionVo1.setfBackfile(hwSupervision1.getfBackfile());
			supervisionVo1.setfBackassignstate(hwSupervision1.getfBackassignstate());
			supervisionVo1.setIsStagestate(hwSupervision1.getIsStagestate());

			// 督导附件数据
			EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
			annexesFile.eq("F_FolderId", hwSupervision1.getfBackfile());
			List<HwBaseAnnexesfile> list = hwBaseAnnexesfileMapper.selectList(annexesFile);
			supervisionVo1.setFuJan(list);
			supervisionVo.add(supervisionVo1);
		}
		// 督导表
		result.put("checkTheSupervision", supervisionVo);
		// 交警执法
		HwCasePoliceoper hCasePoliceoper = new HwCasePoliceoper();
		hCasePoliceoper.setfMainid(fCaseid);
		HwCasePoliceoper hwCasePoliceoper = hwCasePoliceoperMapper.selectOne(hCasePoliceoper);
		CasePoliceoperVo casePoliceoperVo = new CasePoliceoperVo();
		if (hwCasePoliceoper != null) {
			casePoliceoperVo.setfAccount(hwCasePoliceoper.getfAccount());
			casePoliceoperVo.setfAccountname(hwCasePoliceoper.getfAccountname());
			casePoliceoperVo.setfMainid(hwCasePoliceoper.getfMainid());
			casePoliceoperVo.setfOverrunid(hwCasePoliceoper.getfOverrunid());
			casePoliceoperVo.setfPoliceoperid(hwCasePoliceoper.getfPoliceoperid());
			casePoliceoperVo.setfPunishamount(hwCasePoliceoper.getfPunishamount());
			casePoliceoperVo.setfPunishdatetime(hwCasePoliceoper.getfPunishdatetime());
			casePoliceoperVo.setfPunishfile(hwCasePoliceoper.getfPunishfile());
			casePoliceoperVo.setfPunishremak(hwCasePoliceoper.getfPunishremak());
			casePoliceoperVo.setfPunishresult(hwCasePoliceoper.getfPunishresult());
			casePoliceoperVo.setfPunishscore(hwCasePoliceoper.getfPunishscore());
			casePoliceoperVo.setfPunishusername(hwCasePoliceoper.getfPunishusername());
			casePoliceoperVo.setfPunishuserphone(hwCasePoliceoper.getfPunishuserphone());
			if (hwCasePoliceoper.getfPunishfile() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hwCasePoliceoper.getfPunishfile());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist1 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				casePoliceoperVo.setHwBaseAnnexesfilelist(hwBaseAnnexesfilelist1);

			}
		}
		result.put("HwCasePoliceoper", casePoliceoperVo);

		// 案件附件表
		List<HwBaseAnnexesfile> hwBaseAnnexesfilelist = new ArrayList<HwBaseAnnexesfile>();
		// 源头倒查表 ：HW_Case_SrcCom
		HwCaseSrccom hwCaseSrccom = new HwCaseSrccom();
		hwCaseSrccom.setfMainid(fCaseid);
		HwCaseSrccom hCaseSrccom = hwCaseSrccomMapper.selectOne(hwCaseSrccom);
		CaseSrccomVo caseSrccomVo = new CaseSrccomVo();
		if (hCaseSrccom != null) {
			caseSrccomVo.setfMainid(hCaseSrccom.getfMainid());
			caseSrccomVo.setfOpertime(hCaseSrccom.getfOpertime());
			caseSrccomVo.setfOperuser(hCaseSrccom.getfOperuser());
			caseSrccomVo.setfOperuserid(hCaseSrccom.getfOperuserid());
			caseSrccomVo.setfOperusername(hCaseSrccom.getfOperusername());
			caseSrccomVo.setfOperuserphone(hCaseSrccom.getfOperuserphone());
			caseSrccomVo.setfOverrunid(hCaseSrccom.getfOverrunid());
			caseSrccomVo.setfRemark(hCaseSrccom.getfRemark());
			caseSrccomVo.setfRemarkfile(hCaseSrccom.getfRemarkfile());
			caseSrccomVo.setfSrcamount(hCaseSrccom.getfSrcamount());
			caseSrccomVo.setfSrccomid(hCaseSrccom.getfSrccomid());
			caseSrccomVo.setfSrcgoodsannex(hCaseSrccom.getfSrcgoodsannex());
			caseSrccomVo.setfSrcpunishannex(hCaseSrccom.getfSrcpunishannex());
			caseSrccomVo.setfTosrccomid(hCaseSrccom.getfTosrccomid());
			caseSrccomVo.setfTosrccomname(hCaseSrccom.getfTosrccomname());

			if (hCaseSrccom.getfRemarkfile() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSrccom.getfRemarkfile());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist2 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist2);
			}

			if (hCaseSrccom.getfSrcgoodsannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSrccom.getfSrcgoodsannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist3 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist3);
			}

			if (hCaseSrccom.getfSrcpunishannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSrccom.getfSrcpunishannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist4 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist4);
			}
			caseSrccomVo.setHwBaseAnnexesfilelist(hwBaseAnnexesfilelist);
		}
		result.put("HwCaseSrccom", caseSrccomVo);

		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, result);
	}

	// 详情2
	public Map<String, Object> queryDetail(String fCaseid) {

		HashMap<String, Object> result = new HashMap<String, Object>();
		// 案件表
		HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(fCaseid);
		if (hwCaseMain.getfAjCasetype() != null) {
			// 案件站点办理表更新
			HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
			hwCaseSiteoper.setfMainid(fCaseid);
			HwCaseSiteoper hCaseSiteoper = hwCaseSiteoperMapper.selectOne(hwCaseSiteoper);
			result.put("HwCaseSiteoper", hCaseSiteoper);
			// 案件附件表
			List<HwBaseAnnexesfile> hwBaseAnnexesfilelist = new ArrayList<HwBaseAnnexesfile>();
			if (hCaseSiteoper.getfFirstviewannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfFirstviewannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist1 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist1);

			}
			if (hCaseSiteoper.getfReviewannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfReviewannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist2 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist2);

			}
			if (hCaseSiteoper.getfTranannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfTranannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist3 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist3);
			}
			if (hCaseSiteoper.getfCopyannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfCopyannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist4 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist4);
			}
			if (hCaseSiteoper.getfFourlicannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSiteoper.getfFourlicannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist5 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist5);
			}

			result.put("HwBaseAnnexesfile", hwBaseAnnexesfilelist);
			// HW_Case_File 案件文书上传表
			List<Map<String, Object>> maps = hwCaseFileMapper.dyGetUserList(fCaseid, hwCaseMain.getfAjCasetype());
			result.put("HwCaseFile", maps);
		}
		result.put("HwCaseMain", hwCaseMain);

		// 超重数据
		HwDataOverrunstationHistory history = hwDataOverrunstationHistoryMapper.selectById(hwCaseMain.getfOverrunid());
		result.put("HwDataOverrunstationHistory", history);
		// 督导表
		EntityWrapper<HwSupervision> supervision = new EntityWrapper<HwSupervision>();
		supervision.eq("F_FromObjectID", fCaseid);
		List<HwSupervision> hwSupervisions = hwSupervisionMapper.selectList(supervision);
		List<SupervisionVo> supervisionVo = new ArrayList<>();
		for (HwSupervision hwSupervision1 : hwSupervisions) {
			SupervisionVo supervisionVo1 = new SupervisionVo();
			supervisionVo1.setfSpvid(hwSupervision1.getfSpvid());
			supervisionVo1.setfFromobjectid(hwSupervision1.getfFromobjectid());
			supervisionVo1.setfFromtype(hwSupervision1.getfFromtype());
			supervisionVo1.setfFromdepcode(hwSupervision1.getfFromdepcode());
			supervisionVo1.setfFromuserid(hwSupervision1.getfFromuserid());
			supervisionVo1.setfFromusername(hwSupervision1.getfFromusername());
			supervisionVo1.setfFromtime(hwSupervision1.getfFromtime());
			supervisionVo1.setfTitle(hwSupervision1.getfTitle());
			supervisionVo1.setfFromsrc(hwSupervision1.getfFromsrc());
			supervisionVo1.setfSpvcontent(hwSupervision1.getfSpvcontent());
			supervisionVo1.setfCurrentstep(hwSupervision1.getfCurrentstep());
			supervisionVo1.setfBacktype(hwSupervision1.getfBacktype());
			supervisionVo1.setfBackdepcode(hwSupervision1.getfBackdepcode());
			supervisionVo1.setfBackdepname(hwSupervision1.getfBackdepname());
			supervisionVo1.setfBackuserid(hwSupervision1.getfBackuserid());
			supervisionVo1.setfBackusername(hwSupervision1.getfBackusername());
			supervisionVo1.setfBackuserphone(hwSupervision1.getfBackuserphone());
			supervisionVo1.setfBacktime(hwSupervision1.getfBacktime());
			supervisionVo1.setfBackfile(hwSupervision1.getfBackfile());
			supervisionVo1.setfBackassignstate(hwSupervision1.getfBackassignstate());
			supervisionVo1.setIsStagestate(hwSupervision1.getIsStagestate());

			// 督导附件数据
			EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
			annexesFile.eq("F_FolderId", hwSupervision1.getfBackfile());
			List<HwBaseAnnexesfile> list = hwBaseAnnexesfileMapper.selectList(annexesFile);
			supervisionVo1.setFuJan(list);
			supervisionVo.add(supervisionVo1);
		}
		// 督导表
		result.put("checkTheSupervision", supervisionVo);
		// 交警执法
		HwCasePoliceoper hCasePoliceoper = new HwCasePoliceoper();
		hCasePoliceoper.setfMainid(fCaseid);
		HwCasePoliceoper hwCasePoliceoper = hwCasePoliceoperMapper.selectOne(hCasePoliceoper);
		CasePoliceoperVo casePoliceoperVo = new CasePoliceoperVo();
		if (hwCasePoliceoper != null) {
			casePoliceoperVo.setfAccount(hwCasePoliceoper.getfAccount());
			casePoliceoperVo.setfAccountname(hwCasePoliceoper.getfAccountname());
			casePoliceoperVo.setfMainid(hwCasePoliceoper.getfMainid());
			casePoliceoperVo.setfOverrunid(hwCasePoliceoper.getfOverrunid());
			casePoliceoperVo.setfPoliceoperid(hwCasePoliceoper.getfPoliceoperid());
			casePoliceoperVo.setfPunishamount(hwCasePoliceoper.getfPunishamount());
			casePoliceoperVo.setfPunishdatetime(hwCasePoliceoper.getfPunishdatetime());
			casePoliceoperVo.setfPunishfile(hwCasePoliceoper.getfPunishfile());
			casePoliceoperVo.setfPunishremak(hwCasePoliceoper.getfPunishremak());
			casePoliceoperVo.setfPunishresult(hwCasePoliceoper.getfPunishresult());
			casePoliceoperVo.setfPunishscore(hwCasePoliceoper.getfPunishscore());
			casePoliceoperVo.setfPunishusername(hwCasePoliceoper.getfPunishusername());
			casePoliceoperVo.setfPunishuserphone(hwCasePoliceoper.getfPunishuserphone());

			if (hwCasePoliceoper.getfPunishfile() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hwCasePoliceoper.getfPunishfile());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist1 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				casePoliceoperVo.setHwBaseAnnexesfilelist(hwBaseAnnexesfilelist1);

			}

		}
		result.put("HwCasePoliceoper", casePoliceoperVo);

		// 案件附件表
		List<HwBaseAnnexesfile> hwBaseAnnexesfilelist = new ArrayList<HwBaseAnnexesfile>();

		// 源头倒查表 ：HW_Case_SrcCom
		HwCaseSrccom hwCaseSrccom = new HwCaseSrccom();
		hwCaseSrccom.setfMainid(fCaseid);
		HwCaseSrccom hCaseSrccom = hwCaseSrccomMapper.selectOne(hwCaseSrccom);
		CaseSrccomVo caseSrccomVo = new CaseSrccomVo();
		if (hCaseSrccom != null) {
			caseSrccomVo.setfMainid(hCaseSrccom.getfMainid());
			caseSrccomVo.setfOpertime(hCaseSrccom.getfOpertime());
			caseSrccomVo.setfOperuser(hCaseSrccom.getfOperuser());
			caseSrccomVo.setfOperuserid(hCaseSrccom.getfOperuserid());
			caseSrccomVo.setfOperusername(hCaseSrccom.getfOperusername());
			caseSrccomVo.setfOperuserphone(hCaseSrccom.getfOperuserphone());
			caseSrccomVo.setfOverrunid(hCaseSrccom.getfOverrunid());
			caseSrccomVo.setfRemark(hCaseSrccom.getfRemark());
			caseSrccomVo.setfRemarkfile(hCaseSrccom.getfRemarkfile());
			caseSrccomVo.setfSrcamount(hCaseSrccom.getfSrcamount());
			caseSrccomVo.setfSrccomid(hCaseSrccom.getfSrccomid());
			caseSrccomVo.setfSrcgoodsannex(hCaseSrccom.getfSrcgoodsannex());
			caseSrccomVo.setfSrcpunishannex(hCaseSrccom.getfSrcpunishannex());
			caseSrccomVo.setfTosrccomid(hCaseSrccom.getfTosrccomid());
			caseSrccomVo.setfTosrccomname(hCaseSrccom.getfTosrccomname());

			if (hCaseSrccom.getfRemarkfile() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSrccom.getfRemarkfile());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist2 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist2);
			}

			if (hCaseSrccom.getfSrcgoodsannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSrccom.getfSrcgoodsannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist3 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist3);
			}

			if (hCaseSrccom.getfSrcpunishannex() != null) {
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId", hCaseSrccom.getfSrcpunishannex());
				List<HwBaseAnnexesfile> hwBaseAnnexesfilelist4 = hwBaseAnnexesfileMapper.selectList(annexesFile);
				hwBaseAnnexesfilelist.addAll(hwBaseAnnexesfilelist4);
			}
			caseSrccomVo.setHwBaseAnnexesfilelist(hwBaseAnnexesfilelist);
		}
		result.put("HwCaseSrccom", caseSrccomVo);

		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, result);
	}
}
